// 存放的页面
//渲染购物车列表 就引入store  因为购物车的状态 在store里面
import { useState } from "react";
import store from "../redux";
import { removeCartActions } from "../redux/action/getCartAction";
import { setSexActions } from "../redux/action/userActions";
export default function Cart() {
  // console.log(store.getState().cartList);
  // 为了是响应式的  所以定义状态
  let [list, setList] = useState(store.getState().cartReducer.cartList);
  // 订阅一下
  store.subscribe(() => {
    setList(store.getState().cartReducer.cartList);
  });
  return (
    <div>
      <h2>Cart</h2>
      <ol>
        {list.map((item, index) => {
          //item 是渲染的每一个商品名称
          return (
            <li
              key={index}
              onClick={() => {
                store.dispatch(removeCartActions(index));
              }}
            >
              {item}
            </li>
          );
        })}
      </ol>
      <button onClick={()=>{
        store.dispatch(setSexActions("女"))
      }}>修改用户性别</button>
    </div>
  );
}
